package com.leetcode.LeetCode精选TOP面试题;

import com.leetcode.common.model.TreeNode;

/**
 * @author 覃国强
 * @date 2022-06-07 18:53
 */
public class 题库_0098_验证二叉搜索树 {

  static
  class Solution {
    public boolean isValidBST(TreeNode root) {
      return helper(root, null, null);
    }

    private boolean helper(TreeNode root, Integer min, Integer max) {
      if (root == null) {
        return true;
      }
      if ((min != null && root.val <= min) || (max != null && root.val >= max)) {
        return false;
      }
      return helper(root.left, min, root.val) && helper(root.right, root.val, max);
    }
  }

}
